<?php
	/*
	 * File: core_api.php
	 * Last modification: 20.07.2011
	 * Author(s): kivio.wanderley
	 * 
	 */
?>

<?php
	
	# Paths
	$g_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
	$g_css_href = 'css/';
	$g_js_href = 'js/';
	
//	global $g_lang_dir;
	$g_lang_dir = $g_core_dir.'lang'.DIRECTORY_SEPARATOR; 
	
	# APIs
  //require_once( $g_core_dir . 'config_defaults.php' );
	require_once( $g_core_dir . 'constant_inc.php' );
	require_once( $g_core_dir . 'gpc_api.php' );
	require_once( $g_core_dir . 'lang_api.php' );
	require_once( $g_core_dir . 'print_api.php' );
	require_once( $g_core_dir . 'html_api.php' );
	require_once( $g_core_dir . 'datab_api.php' );
	require_once( $g_core_dir . 'datab_user_api.php' );
	require_once( $g_core_dir . 'auth_api.php' );
	require_once( $g_core_dir . 'config_api.php' );
	require_once( $g_core_dir . 'info_api.php' );
	
	/**
	 * Require a CSS file.
	 * @param (string) $p_name File name;
	 */
	function core_require_css($p_name) {
		global $g_css_href;

		echo '<link rel="stylesheet" type="text/css" href="'.$g_css_href.$p_name.'.css" />', "\n";
	}
	
	/**
	 * Require a JS file.
	 * @param (string) $p_name File name;
	 */
	function core_require_js($p_name) {
		global $g_js_href;
		
		echo '<script src="'.$g_js_href.$p_name.'.js"></script>', "\n";
	}
	function core_require_js_others() {
		$jquery = "1.6.2";
		$jquery_ui = "1.8.11";
		
		echo '<noscript><meta http-equiv="Refresh" content="1; url=http://localhost/myown"></noscript>', "\n";
		
		echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/'.$jquery.'/jquery.min.js"></script>', "\n";
		echo '<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/'.$jquery_ui.'/jquery-ui.min.js"></script>', "\n";
	}
	
	/**
	 * Require any file from a directory.
	 * @param (string) $p_name File name;
	 * @param (string) $p_dir Directory path;
	 * @param (string) $p_extension File extension;
	 */
	function core_require($p_name, $p_dir, $p_extension) {
		$t_pointer = opendir($p_dir);
		
		while ($t_name_itens = readdir($t_pointer)) {
	        $t_itens[] = $t_name_itens;
	    }
	    sort( $t_itens );
	
	    for( $i = sizeof($t_itens); $i > 0; $i-- ) {
	         if( strstr( $t_itens[$i], $p_name.$p_extension ) ) {
	         	require_once( $p_dir . $t_itens[$i] );
	         }
	    }
	}
	
?>